<%@page import="com.wframe.framework.util.UploadUtil" %>
<%@ page language="java" pageEncoding="utf-8" %>
<%@taglib uri="/WEB-INF/page-base.tld" prefix="w"%>
<%@ include file="/plugins/plupload2/plupload.jsp" %>
<script type="text/javascript" src="<%=request.getContextPath() %>/plugins/oss/upload.js"></script>

<%
    String path = request.getContextPath();
    request.setAttribute("fileserver", UploadUtil.getConfig().getDownserver());
%>
<style>
    .pl_upimgdiv img {
        max-width: 100%
    }
</style>
<script>
    var channeluploader;
    function selchannelimg() {

    }
    function delplphoto(fid, bl) {
        try {
            var f = channeluploader.getFile(fid);
            channeluploader.removeFile(f);
        } catch (e) {
        }
        $('#plfile_' + fid).remove();
    }
    var saveing = false;
    function savechannelA() {
        var obj = $getByName("bean.image", $w.currWin());
        if ((obj.length == 0 || obj.val() == '') && channeluploader.files.length == 0) {
            window.parent.$w.infoMsg("请上传栏目图片")
        } else {
            if (!saveing) {
                saveing = true;
                if (channeluploader.files.length > 0) channeluploader.start();
                else savechannelSubmit();
            }
        }
    }
    function savechannelSubmit() {
        $w.doWinForm(function (re) {
            saveing = false;
            if(re.state=='ok'){
                var reobj={"id":re.id,"title":$getByName("bean.name",$w.currWin()).val()};
                $w.closeCurrWin(reobj);
            }
        });
    }
</script>

<div class="easyui-panel" data-options="doSize:false,layoutH:47,border:false" style="margin:5px">
    <form method="post" action="/floor/UiFloorProductPage@update.page" class="pageForm">
        <w:hidden bind="bean.id"/>
        <w:hidden bind="bean.ui_floor_panel_id"/>
        <div class="ui-formContent">
            <p>
                <label style="width:130px;text-align:right"><font class="red">*</font>类目名称：</label>
                <w:text bind="bean.title" styleClass="easyui-validatebox" dataOptions="required:true"  style="width:400px"/>
            </p>
            <table cellpadding="0" cellspacing="0">
                <tr>
                    <td valign="top" style="padding-top:4px;"><label style="width:130px;text-align:right"><font
                            class="red">*</font>类目图片：</label></td>
                    <td valign="top" style="width:200px;padding-top:4px;padding-left:4px;" id="channelimg">
                         <w:notEqual bind="bean.image" value="">
                             <w:hidden bind="bean.image"/>
                             <img src="${fileserver }<w:write bind="bean.image"/>" style="width:200px">
                         </w:notEqual>
                         <w:equal bind="bean.image" value="">
                             <img src="<%=path %>/images/selimg.png" style="width:200px">
                         </w:equal>
                    </td>
                    <td valign="top" style="padding-top:4px;padding-left:4px;">
                        <a href="javascript:void(0);" class="ui_btn" id="channelimgbtn"
                           onclick="selchannelimg()">选择图片</a>
                        <!-- <p class="red" style="color:red">建议上传1024*300尺寸图片</p> -->
                    </td>
                </tr>
            </table>
            <p style="clear:both">
                <label style="width:130px;text-align:right">链接网址：</label>
                <w:text bind="bean.link" style="width:400px"/>
            </p>
            <p>
                <label style="width:130px;text-align:right">类目样式：</label>
                <w:text bind="bean.css" style="width:300px;" styleClass="easyui-validatebox"/>
            </p>
            <p style="clear:both">
                <label style="width:130px;text-align:right">排序号：</label>
                <w:text bind="bean.sort_value" style="width:400px" styleClass="easyui-numberbox" dataOptions="required:true"/>
            </p>
            <p>
                <label style="width:130px;text-align:right">备注：</label>
                <w:text bind="bean.remark" style="width:300px;" styleClass="easyui-validatebox"/>
            </p>
        </div>
    </form>
</div>
<div class="ui-buttonBar">
    <a href="javascript:;" class="easyui-linkbutton marginR16" iconCls="icon_save" onclick="savechannelA();">保 存</a>
    <a href="javascript:;" class="easyui-linkbutton" iconCls="icon_cancel" onclick="$w.closeCurrWin()">取 消</a>
</div>
<script>
    var plparm = {
        runtimes: 'html5,flash,silverlight,html4',
        browse_button: 'channelimgbtn',
        flash_swf_url: ctx + '/plugins/plupload/js/Moxie.swf',
        silverlight_xap_url: ctx + '/plugins/plupload/js/Moxie.xap',
        filters: {
            max_file_size: '2mb',
            mime_types: [
                {title: "Image files", extensions: "jpg,gif,png"}
            ]
        },

        init: {
            FilesAdded: function (up, files) {
                $("#channelimg").html('');
                if (files.length > 0) {
                    if (channeluploader.files.length > 1) channeluploader.removeFile(up.files[0]);
                }
                filesAdded(up, files, '#channelimg');
            },
            UploadProgress: function (up, file) {
                uploadProgress(up, file);
            },
            FileUploaded: function (up, file, responseObject) {
                var re = jQuery.parseJSON(responseObject.response);
                $('#plimgurl_' + file.id).val(re.url.replace(re.basepath, ""));
            },
            UploadComplete: function (up, files) {
                savechannelSubmit();
                saveing = false;
            },
            Error: function (up, err) {
                upError(up, err, '2mb');
                saveing = false;
            }
        }
    };

    $oss.setUpDir('info');
    channeluploader = $oss.initUpload(plparm);

    function getPlFileHtml(fid, fpath, name) {
        var p = "/plugins/plupload2/preview.jpg";
        var v = "";
        if (fpath) {
            p = fpath;
            v = fid;
        }
        var putname = "bean.image";
        if (name) putname = name;
        var h = "<div class='pl_upimgdiv' id='plfile_" + fid + "'><img id='plimg" + fid + "' src='" + ctx + p + "'/><div class='file_del'><a href=\"javascript:delplphoto('" + fid + "')\" title='移除'></a></div><div class='file_progress'></div><div class='file_txt'>等待上传</div><input name='" + putname + "' type='hidden' id='plimgurl_" + fid + "' value='" + v + "'></div>";
        return h;
    }
</script>